home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
diskmags
/
4671-5.790
/
dmg-5786
/
fastlife
/
fasterli.bas
next >
Wrap
BASIC Source File
|
1990-05-08
|
6KB
|
198 lines
' LIFE (C) Peter Augustin September 1989
DEFINT a-z
CONST LEFT=1,RIGHT=2,MINUSONE=-1,ONE=1,TWO=2,THREE=3
OPTION BASE 0
CHRGAPY=TWO:CHRGAPX=TWO
SETSCREEN X,Y,GENPOS,HE,GAPY,GAPX,CHRGAPY,CHRGAPX
DIM CELLSTATE(Y+ONE,X+ONE),CELLCOUNT(Y+ONE,X+ONE),WORKCOUNT(Y+ONE,X+ONE)
CALL CONFIGURATION(X,Y)
CALL HARDWAY(X,Y)
DO
READMOUSE XPOS,YPOS,BUTTON
IF BUTTON=RIGHT THEN CALL GETICONS(X,Y)
CALL GENERATION(X,Y,GENPOS)
LOOP UNTIL BUTTON=THREE
STOP
SUB HARDWAY(VAL X,VAL Y)
SHARED CELLSTATE(),CELLCOUNT(),WORKCOUNT()
FOR I=ONE TO Y
FOR J=ONE TO X
T=0
FOR K=MINUSONE TO ONE
FOR L=MINUSONE TO ONE
T=T+CELLSTATE(I+K,J+L)
NEXT L,K
CELLCOUNT(I,J)=T-CELLSTATE(I,J)
WORKCOUNT(I,J)=CELLCOUNT(I,J)
CALL DISPLAY(I,J,CELLSTATE(I,J))
NEXT J,I
END SUB
SUB DISPLAY(VAL I,VAL J,VAL STATE)
SHARED CHRGAPY,CHRGAPX
LOCATE (I+CHRGAPY),(J+CHRGAPX),0
COLOR 3
IF STATE=0 THEN
PRINT CHR$(43);
ELSE COLOR 2:PRINT CHR$(6);
END IF
END SUB
SUB GENERATION(VAL X,VAL Y,VAL GENPOS)
SHARED CELLSTATE(),CELLCOUNT(),WORKCOUNT(),GEN
FOR I=ONE TO Y
FOR J=ONE TO X
IF CELLCOUNT(I,J)=THREE AND CELLSTATE(I,J)=0 THEN CALL BORN(I,J)
IF (CELLCOUNT(I,J)<TWO OR CELLCOUNT(I,J)>THREE) AND CELLSTATE(I,J)=ONE THEN CALL DIES(I,J)
NEXT J,I
FOR I=ONE TO Y
FOR J=ONE TO X
CELLCOUNT(I,J)=WORKCOUNT(I,J)
NEXT J,I
INCR GEN
COLOR 1:LOCATE 1,GENPOS,0 :PRINT USING "#####"; GEN
END SUB
SUB BORN(VAL I,VAL J)
SHARED WORKCOUNT(),CELLSTATE(),CHRGAPY,CHRGAPX
CELLSTATE(I,J)=ONE
FOR K=MINUSONE TO ONE
FOR L=MINUSONE TO ONE
INCR WORKCOUNT(I+K,J+L)
NEXT L,K
DECR WORKCOUNT(I,J)
COLOR 2:LOCATE (I+CHRGAPY),(J+CHRGAPX):PRINT CHR$(6);
END SUB
SUB DIES(VAL I,VAL J)
SHARED WORKCOUNT(),CELLSTATE(),CHRGAPY,CHRGAPX
CELLSTATE(I,J)=0
FOR K=MINUSONE TO ONE
FOR L=MINUSONE TO ONE
DECR WORKCOUNT(I+K,J+L)
NEXT L,K
INCR WORKCOUNT(I,J)
COLOR 3:LOCATE (I+CHRGAPY),(J+CHRGAPX):PRINT CHR$(43);
END SUB
SUB READMOUSE(XPOS,YPOS,BUTTON)
XPOS=MOUSE(0)
YPOS=MOUSE(1)
BUTTON=MOUSE(2)
END SUB
SUB GETICONS(VAL X,VAL Y)
SHARED GAPY,HE,GENPOS,GEN
MOUSE 0
DO
DO
READMOUSE XPOS,YPOS,BUTTON
SC=YPOS
SELECT CASE SC
CASE 0 TO 9 :ICONBAR XPOS,CODENUM
CASE GAPY+3 TO (Y*HE)+GAPY+2:IF XPOS>=16 AND XPOS<=(X*8)+15 THEN
CELLGRID XPOS,YPOS,XCELL,YCELL,CELL,CODENUM:MOUSE -1
ELSE MOUSE 0'numbers
END IF
CASE ELSE CODENUM=0:MOUSE 0
END SELECT
LOOP UNTIL BUTTON=LEFT AND CODENUM<>0
SELECT CASE CODENUM
CASE ONE :CALL RCELLGRID (XCELL,YCELL,CELL,CODENUM)
CASE TWO :CALL RCLEAR(CODENUM)
CASE THREE:CALL RGEN(CODENUM)
END SELECT
LOOP UNTIL CODENUM=99
MOUSE -1
END SUB
SUB SETSCREEN (X,Y,GENPOS,HE,GAPY,GAPX,CHRGAPY,CHRGAPX)
GRAPHMOD=PEEKW(SYSTAB)
SELECT CASE GRAPHMOD
CASE=4
Y=19:X=36:GENPOS=35:SIZE=TWO:HEIGHT=2 'LOW RES
CASE=2
Y=19:X=76:GENPOS=70:SIZE=ONE:HEIGHT=2 'MED RES
CASE=1
Y=19:X=76:GENPOS=70:SIZE=ONE:HEIGHT=1 'HIGH RES
END SELECT
MOUSE -1
HE=18/HEIGHT:GAPY=CHRGAPY*HE:GAPX=CHRGAPX*8
WINDOW OPEN 2,"",0,0,640/SIZE,400/HEIGHT,0
COLOR 1,1,1,4,2
'BOX CELL GRID
LINEF 0,10,640/SIZE,10'FINISH WINDOW
LINEF GAPX-TWO,GAPY,(8*X)+GAPX+TWO,GAPY
LINEF GAPX-TWO,GAPY,GAPX-TWO,(HE*Y)+GAPY+TWO
LINEF (8*X)+GAPX+TWO,GAPY,(8*X)+GAPX+TWO,(HE*Y)+GAPY+TWO
LINEF GAPX-TWO,(HE*Y)+GAPY+TWO,(8*X)+GAPX+TWO,(HE*Y)+GAPY+TWO
FILL 0,11
LOCATE 1,3,0:PRINT" CLEAR START "
COLOR 1:LOCATE 1,GENPOS,0 :PRINT USING "#####"; GEN
END SUB
SUB CONFIGURATION(VAL X,VAL Y)
SHARED CELLSTATE()
C=Y+ONE:D=X+ONE
FOR I=ONE TO Y
CELLSTATE(I,I)=ONE
CELLSTATE(C-I,I)=ONE
CELLSTATE(I,D-I)=ONE
CELLSTATE(C-I,D-I)=ONE
NEXT I
END SUB
SUB ICONBAR(VAL XPOS,CODENUM)
SHARED GENPOS,GEN
STATIC COPYXCHR
XCHR=INT(XPOS/8)+1
IF COPYXCHR=XCHR THEN EXIT SUB
LOCATE 1,3,0:PRINT" CLEAR START "
LOCATE 1,GENPOS,0:PRINT USING"#####";GEN
COLOR 2
SELECT CASE XCHR
CASE 4 TO 10:
LOCATE 1,4,0:PRINT "|CLEAR|":CODENUM=2
CASE 11 TO 18:LOCATE 1,11,0:PRINT "|START|":CODENUM=99
CASE GENPOS TO GENPOS+5:LOCATE 1,GENPOS,0:PRINT USING"#####";GEN:CODENUM=3
CASE ELSE :CODENUM=0
END SELECT
COLOR 1
COPYXCHR=XCHR
END SUB
SUB RCLEAR(CODENUM)
SHARED CELLSTATE(),WORKCOUNT(),CELLCOUNT(),X,Y,CHRGAPY,CHRGAPX
FOR I=ONE TO Y
FOR J=ONE TO X
IF WORKCOUNT(I,J)>0 THEN WORKCOUNT(I,J)=0:COLOR 3:LOCATE (I+CHRGAPY),(CHRGAPX+J):PRINT CHR$(43);
CELLSTATE(I,J)=0
CELLCOUNT(I,J)=WORKCOUNT(I,J)
NEXT J,I
CODENUM=0
END SUB
SUB RGEN(CODENUM)
SHARED GEN,GENPOS
GEN=0
LOCATE 1,GENPOS,0:PRINT USING "#####";GEN
CODENUM=0
END SUB
SUB CELLGRID(VAL XPOS,VAL YPOS,XCELL,YCELL,CELL,CODENUM)
SHARED CELLSTATE(),CHRGAPY,CHRGAPX,GAPY,HE
STATIC COPYX,COPYY,CELL,CODENUM
XCELL=INT((XPOS-16)/8)+1:YCELL=INT((YPOS-(GAPY+3))/HE)+1
IF XCELL=COPYX AND YCELL=COPYY THEN EXIT SUB
IF COPYX<=0 THEN GOTO JUMP
LOCATE (COPYY+CHRGAPY),(COPYX+CHRGAPX),0
COPYCELL=CELLSTATE(COPYY,COPYX)
IF COPYCELL=0 THEN COLOR 3:PRINT CHR$(43); ELSE COLOR 2:PRINT CHR$(6);
JUMP:
LOCATE (YCELL+CHRGAPY),(XCELL+CHRGAPX),0
CELL=CELLSTATE(YCELL,XCELL)
IF CELL=0 THEN COLOR 3:PRINT CHR$(189); ELSE COLOR 2:PRINT CHR$(189);
COPYX=XCELL:COPYY=YCELL:CODENUM=1
COLOR 1
END SUB
SUB RCELLGRID(VAL XCELL,VAL YCELL,VAL CELL,CODENUM)
SHARED WORKCOUNT(),CELLCOUNT()
IF CELL=0 THEN
CALL BORN(YCELL,XCELL)
ELSE CALL DIES(YCELL,XCELL)
END IF
FOR K=MINUSONE TO ONE
FOR L=MINUSONE TO ONE
CELLCOUNT(YCELL+K,XCELL+L)=WORKCOUNT(YCELL+K,XCELL+L)
NEXT L,K
CODENUM=0
END SUB